import React from 'react';
import cn from 'classnames';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import { Card } from 'antd';
// import { getTaskInfo } from '../../../../services/task';
import styles from './FilePreview.less';

const FilePreview = ({ location }) => {
    const { query } = location;

    // 根据文件名返回格式，比如a.pdf 返回pdf
    const getFileType = name => name.split('.')[1].toLowerCase();
    const renderIframe = file => {
        if (file.length > 0) {
            // 将s3替换成oss
            const docUrl = encodeURIComponent(file[0].url);
            const url = `https://view.officeapps.live.com/op/view.aspx?src=${docUrl}`;
            return file[0].url ? (
                <div className={cn(styles.textWrap, styles[getFileType(file[0].originName)])}>
                    <div className={styles.maskTop}>
                        <i className={styles.logo} />
                        微微科技内部文件，仅供查看
                    </div>
                    <div className={styles.maskBottom} />
                    <iframe
                        title="制度文件"
                        style={{
                            width: '100%',
                            height: '600px',
                            border: 0
                        }}
                        src={url}
                    ></iframe>
                </div>
            ) : (
                ''
            );
        }
        return '';
    };

    return (
        <PageHeaderWrapper>
            <Card bordered={false}>
                <div className={styles.textWrap}>
                    <div className={styles.maskTop}>微微科技内部文件，仅供查看</div>
                    <div className={styles.maskBottom} />
                    {query.file ? renderIframe(query.file) : ''}
                </div>
            </Card>
        </PageHeaderWrapper>
    );
};

export default FilePreview;
